@extends('layout.page')
@section('title','题库 - 列表')
@section('stylesheet')
    <!-- Sweet Alert -->
    <link href="/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet">
@endsection

@section('static-page')
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>题库列表<small></small></h5>
            </div>
            <div class="ibox-content">
                <div class="">
                    {{----}}
                    <a href="/quetions/create" class="btn btn-primary _addclick">添加 </a>
                </div>
                {{--搜索分页代码块--}}
                <div class="row">
                    <form action="" method="get">
                        <div><b>类型</b></div>
                        <div class="col-sm-2 m-b-xs">
                            <select name="platform" class="form-control input-s-sm inline">
                                @foreach($types as $key=>$val)
                                    <option @if($val['id'] == $currentType) selected @endif value="{{$val['id']}}">{{$val['title']}}</option>
                                @endforeach
                            </select>
                        </div>
                    </form>
                </div>


                <table class="table table-striped table-bordered table-hover">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>排序</th>
                            <th>标题</th>
                            <th>类型</th>

                            <th>考试时间</th>
                            <th>多少人做过</th>
                            <th>平均分</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    @foreach($quesions as $quesion)
                        <tr class="gradeA">
                            <td>{{ $quesion->id }}</td>
                            <td>{{ $quesion->sort }}</td>
                            <td>{{ $quesion->title }}</td>

                            <td>{{ $types[$quesion->type]['title'] }}</td>

                            <td>{{ date('Y-m-d'.$quesion->exam_time) }}</td>
                            <td>{{ $quesion->number }}</td>
                            <td>{{ $quesion->average }}</td>
                            <td class="center">
                                <a href="/ceb/advertistment/edit">编辑</a>
                                <a href="/ceb/advertistment/edit">|添加题目</a>
                                <a href="javascript:void(0);" class="delete-product" data-val="">|删除</a>
                            </td>
                        </tr>

                    @endforeach

                    </tbody>
                    <tfoot>
                        <tr>
                            <th>ID</th>
                            <th>排序</th>
                            <th>标题</th>
                            <th>类型</th>

                            <th>考试时间</th>
                            <th>多少人做过</th>
                            <th>平均分</th>
                            <th>操作</th>
                        </tr>
                    </tfoot>
                </table>
                {{--分页--}}
                <div>
                    <div class="pull-right">
                        {!! $quesions->render() !!}
                    </div>
                </div>

            </div>
        </div>
    </div>
@endsection

@section('javascript')
    <!-- Sweet alert -->
    <script src="/js/plugins/sweetalert/sweetalert.min.js"></script>
    <script src="/js/plugins/fancybox/jquery.fancybox.js"></script>
    <script>
        $(document).ready(function () {

            $('.delete-product').click(function () {
                var id = $(this).data('val');
                var docuElem=$(this);
                swal({
                            title: "您确定要删除这条信息吗",
                            text: "删除后将无法恢复，请谨慎操作！",
                            type: "warning",
                            showCancelButton: true,
                            confirmButtonColor: "#DD6B55",
                            confirmButtonText: "删除！",
                            cancelButtonText: "取消",
                            closeOnConfirm: false,
                            closeOnCancel: false
                        },
                        function (isConfirm) {
                            if (isConfirm) {
                                //继续执行
                                $.ajaxSetup({
                                    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' }
                                });
                                $.ajax({
                                    type:'post',
                                    url:'/ceb/advertistment/delete',
                                    dataType:'json',
                                    data:{id:id},
                                    success: function(data){
                                        data=eval(data);
                                        console.log(data.code);
                                        if(data.code==1){
                                            docuElem.parents('.gradeA').remove();
                                            swal({
                                                title: "操作成功",
                                                type: "success",
                                                timer: 1000,
                                                showCancelButton: false,
                                                closeOnConfirm: false,
                                                closeOnCancel: false
                                            });
                                        }else{
                                            swal({
                                                title: data.message,
                                                type: "error",
                                                timer: 1000,
                                                showCancelButton: false,
                                                closeOnConfirm: false,
                                                closeOnCancel: false
                                            });
                                        }
                                    }
                                });

                            } else {
                                swal({
                                    title: "您取消了删除操作！",
                                    type: "error",
                                    timer: 1000,
                                    showCancelButton: false,
                                    closeOnConfirm: false,
                                    closeOnCancel: false
                                });

                            }
                        }
                );

                return false;

            });
            //====name=""
            $("select[name='platform']").change(function () {
                $('form').submit();
            });
            $("select[name='int_splace']").change(function () {
                $('form').submit();
            });

            $('.fancybox').fancybox({
                openEffect: 'none',
                closeEffect: 'none'
            });

        });

    </script>

@endsection
